package com.android.bookgarden.views;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.android.bookgarden.R;

/**
 * Create by zouqh
 * on 2018/12/16
 **/
public class LoadingDialog extends Dialog {

    private static LoadingDialog dialog ;
    public LoadingDialog(@NonNull Context context) {
        super(context);

    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context,  R.style.CustomDialog);
    }


    public static LoadingDialog showMassge(Context context,String msg){
        dialog = new LoadingDialog(context,R.style.CustomDialog);
        dialog.setContentView(R.layout.loading_view);
        TextView text = dialog.findViewById(R.id.mssage);
        text.setText(msg);
        dialog.setCancelable(false);
        // 设置居中
        dialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        dialog.getWindow().setAttributes(lp);
        dialog.show();
        return dialog;
    }

    public static void hideProgress() {
        if (null != dialog && dialog.isShowing()) {
            dialog.dismiss();
        }

    }
}
